/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package undermensch.ckeditortest;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

/**
 *
 * @author spencerj
 */
@ManagedBean
@ViewScoped
public class Testbean implements Serializable {

    private String words;
    private List<String> buttons;
    private int currentPage = 1;
    private boolean dirty = false;

    /**
     * Creates a new instance of Testbean
     */
    public Testbean() {
    }

    @PostConstruct
    public void initialize() {
        buttons = new ArrayList<String>();
        buttons.add("1");
        buttons.add("2");
        buttons.add("3");
        buttons.add("4");
    }

    public String getWords() {
        return words;
    }

    public void setWords(String words) {
        this.words = words;
    }

    public List<String> getButtons() {
        return buttons;
    }

    public void setButtons(List<String> buttons) {
        this.buttons = buttons;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public void loadNextPage(ActionEvent event) {
        currentPage++;
    }

    public void loadPreviousPage(ActionEvent event) {
        currentPage--;
    }

    public void loadFirstPage(ActionEvent event) {
        currentPage = 1;
    }

    public void loadLastPage(ActionEvent event) {
        currentPage = 3;
    }

    public void loadSpecificPage(ActionEvent event) {
        FacesContext context = FacesContext.getCurrentInstance();
        Map<String, String> params = context.getExternalContext().getRequestParameterMap();
        currentPage = Integer.parseInt(params.get("page"));
    }
    
    public void handleResponse() {
        dirty = true;        
    }
}
